package com.ssm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.entity.ElcComment;
import com.ssm.entity.ElcInfotype;
import com.ssm.service.ElcCommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (ElcComment)评论管理
 *
 * @author makejava
 * @since 2021-06-01 10:37:19
 */
@RestController
@RequestMapping("elcComment")
public class ElcCommentController {
    /**
     * 服务对象
     */
    @Resource
    private ElcCommentService elcCommentService;


    /**
     * 查找所有的评论信息（分页）
     * @param comment
     * @param rows
     * @param page
     * @return
     */
    @RequestMapping("listComments")
    public PageInfo<ElcComment> queryAll(ElcComment comment,Integer rows,Integer page){
        //分页组件
        PageHelper.startPage(page,rows);
//        查询所有评论信息的方法
        List<ElcComment> list=elcCommentService.queryAll(comment);
        PageInfo<ElcComment> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 查找所有的评论信息（导出表格用）
     * @param elcComment
     * @return
     */
    @RequestMapping("queryAll")
    public List<ElcComment> queryExcel(ElcComment elcComment){
        List<ElcComment> list=elcCommentService.queryAll(elcComment);
        return list;
    }


    /**
     * 模糊查询
     * @param comment
     * @param rows
     * @param page
     * @return
     */
    @RequestMapping("fuzzyComments")
    public PageInfo<ElcComment> fuzzyQuery(ElcComment comment,Integer rows,Integer page){
        //分页组件
        PageHelper.startPage(page,rows);

        List<ElcComment> list=elcCommentService.fuzzyQuery(comment);
        PageInfo<ElcComment> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }



    /**
     * 通过ID删除单个
     * @param id
     * @return
     */
    @RequestMapping("deleteById/{id}")
    public String deleteById(@PathVariable Integer id){
        elcCommentService.deleteById(id);
        return "success";
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("deletes/{ids}")
    public  String deletes(@PathVariable  Integer[] ids){
        elcCommentService.deleteByIds(ids);
        return  "success";
    }


    /**
     * 通过id查询单个评论
     * @param id
     * @return
     */
    @RequestMapping("queryByid/{id}")
    public ElcComment queryByid(@PathVariable Integer id){
        ElcComment comment=elcCommentService.queryById(id);
        return comment;
    }

    /**
     * 更新审核状态，与通过id查询配合
     * @param comment
     * @return
     */
    @RequestMapping("update")
    public String update(ElcComment comment){
        elcCommentService.update(comment);
        return "success";
    }


}
